/**
 ******************************************************************************
 * @file    zb32l03x_hal_cortex.c
 * @author  MCU Software Team
 * @Version V1.0.0
 * @Date    2022/01/19
 * @brief   CORTEX HAL module driver.
 *          This file provides firmware functions to manage the following
 *          functionalities of the CORTEX:
 *           + Initialization and de-initialization functions
 *           + Peripheral Control functions
 *
 @verbatim
 ==============================================================================
                       ##### How to use this driver #####
 ==============================================================================

   [..]
   *** How to configure Interrupts using CORTEX HAL driver ***
   ===========================================================
   [..]
   This section provides functions allowing to configure the NVIC interrupts (IRQ).
   The Cortex-M0+ exceptions are managed by CMSIS functions.

   (#) Configure the priority of the selected IRQ Channels using HAL_NVIC_SetPriority().
   (#) Enable the selected IRQ Channels using HAL_NVIC_EnableIRQ().
   (#) please refer to programming manual for details in how to configure priority.

    -@- IRQ priority order (sorted by highest to lowest priority):
       (+@) Lowest priority
       (+@) Lowest hardware priority (IRQ number)

   [..]
   *** How to configure Systick using CORTEX HAL driver ***
   ========================================================
   [..]
   Setup SysTick Timer for time base.

  (+) The HAL_SYSTICK_Config()function calls the SysTick_Config() function which
      is a CMSIS function that:
       (++) Configures the SysTick Reload register with value passed as function parameter.
       (++) Configures the SysTick IRQ priority to the lowest value 0x0F.
       (++) Resets the SysTick Counter register.
       (++) Configures the SysTick Counter clock source to be Core Clock Source (HCLK).
       (++) Enables the SysTick Interrupt.
       (++) Starts the SysTick Counter.

  (+) You can change the SysTick Clock source to be HCLK_Div4 by calling the macro
      __HAL_CORTEX_SYSTICKCLK_CONFIG(SYSTICK_CLKSOURCE_HCLK_DIV4) just after the
      HAL_SYSTICK_Config() function call. The __HAL_CORTEX_SYSTICKCLK_CONFIG() macro is defined
      inside the zb32l03x_hal_cortex.h file.

  (+) You can change the SysTick IRQ priority by calling the
      HAL_NVIC_SetPriority(SysTick_IRQn,...) function just after the HAL_SYSTICK_Config() function
      call. The HAL_NVIC_SetPriority() call the NVIC_SetPriority() function which is a CMSIS function.

  (+) To adjust the SysTick time base, use the following formula:

      Reload Value = SysTick Counter Clock (Hz) x  Desired Time base (s)
      (++) Reload Value is the parameter to be passed for HAL_SYSTICK_Config() function
      (++) Reload Value should not exceed 0xFFFFFF

 @endverbatim
 ******************************************************************************
 **/


#include "zb32l03x_hal.h"


/** @defgroup CORTEX CORTEX
 * @brief CORTEX HAL module driver
 * @{
 */

#if defined(HAL_CORTEX_MODULE_ENABLED)


/** @defgroup CORTEX_Exported_Functions CORTEX Exported Functions
 * @{
 */


/** @defgroup CORTEX_Exported_Functions_Group1 Initialization and de-initialization functions
 *  @brief    Initialization and Configuration functions
 *
@verbatim
  ==============================================================================
              ##### Initialization and de-initialization functions #####
  ==============================================================================
    [..]
      This section provides the CORTEX HAL driver functions allowing to configure Interrupts
      Systick functionalities

@endverbatim
  * @{
  */


/**
 * @brief  Sets the priority of an interrupt.
 * @param  IRQn: External interrupt number.
 *         This parameter can be an enumerator of IRQn_Type enumeration
 *
 * @param  Priority: The priority for the IRQn channel.
 *         This parameter can be a value between 0 and 3
 *         A lower priority value indicates a higher priority
 * @retval None
 */
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t Priority)
{
    /* Check the parameters */
    assert_param(IS_NVIC_PRIORITY(Priority));

    NVIC_SetPriority(IRQn, Priority);
}

/**
 * @brief  Enables a device specific interrupt in the NVIC interrupt controller.
 * @note   To configure interrupts priority correctly, the NVIC_PriorityGroupConfig()
 *         function should be called before.
 * @param  IRQn External interrupt number.
 *         This parameter can be an enumerator of IRQn_Type enumeration
 *
 * @retval None
 */
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
{
    /* Check the parameters */
    assert_param(IS_NVIC_DEVICE_IRQ(IRQn));

    /* Enable interrupt */
    NVIC_EnableIRQ(IRQn);
}

/**
 * @brief  Disables a device specific interrupt in the NVIC interrupt controller.
 * @param  IRQn External interrupt number.
 *         This parameter can be an enumerator of IRQn_Type enumeration
 *
 * @retval None
 */
void HAL_NVIC_DisableIRQ(IRQn_Type IRQn)
{
    /* Check the parameters */
    assert_param(IS_NVIC_DEVICE_IRQ(IRQn));

    /* Disable interrupt */
    NVIC_DisableIRQ(IRQn);
}

/**
 * @brief  Initiates a system reset request to reset the MCU.
 * @retval None
 */
void HAL_NVIC_SystemReset(void)
{
    /* System Reset */
    NVIC_SystemReset();
}

/**
 * @brief  Initializes the System Timer and its interrupt, and starts the System Tick Timer.
 *         Counter is in free running mode to generate periodic interrupts.
 * @param  TicksNumb: Specifies the ticks Number of ticks between two interrupts.
 * @retval status:  - 0  Function succeeded.
 *                  - 1  Function failed.
 */
uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb)
{
    return SysTick_Config(TicksNumb);
}
/**
 * @}
 */

/** @defgroup CORTEX_Exported_Functions_Group2 Peripheral Control functions
 *  @brief   Cortex control functions
 *
@verbatim
  ==============================================================================
                      ##### Peripheral Control functions #####
  ==============================================================================
    [..]
      This subsection provides a set of functions allowing to control the CORTEX
      (NVIC, SYSTICK) functionalities.

@endverbatim
  * @{
  */

/**
 * @brief  Gets the priority of an interrupt.
 * @param  IRQn: External interrupt number.
 *         This parameter can be an enumerator of IRQn_Type enumeration
 * @retval None
 */
void HAL_NVIC_GetPriority(IRQn_Type IRQn)
{
    /* Get priority for Cortex-M system or device specific interrupts */
    NVIC_GetPriority(IRQn);
}

/**
 * @brief  Sets Pending bit of an external interrupt.
 * @param  IRQn External interrupt number
 *         This parameter can be an enumerator of IRQn_Type enumeration
 *
 * @retval None
 */
void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn)
{
    /* Check the parameters */
    assert_param(IS_NVIC_DEVICE_IRQ(IRQn));

    /* Set interrupt pending */
    NVIC_SetPendingIRQ(IRQn);
}

/**
 * @brief  Gets Pending Interrupt (reads the pending register in the NVIC
 *         and returns the pending bit for the specified interrupt).
 * @param  IRQn External interrupt number.
 *         This parameter can be an enumerator of IRQn_Type enumeration
 *
 * @retval status: - 0  Interrupt status is not pending.
 *                 - 1  Interrupt status is pending.
 */
uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn)
{
    /* Check the parameters */
    assert_param(IS_NVIC_DEVICE_IRQ(IRQn));

    /* Return 1 if pending else 0 */
    return NVIC_GetPendingIRQ(IRQn);
}

/**
 * @brief  Clears the pending bit of an external interrupt.
 * @param  IRQn External interrupt number.
 *         This parameter can be an enumerator of IRQn_Type enumeration
 *
 * @retval None
 */
void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn)
{
    /* Check the parameters */
    assert_param(IS_NVIC_DEVICE_IRQ(IRQn));

    /* Clear pending interrupt */
    NVIC_ClearPendingIRQ(IRQn);
}


/**
 * @brief  Configures the SysTick clock source.
 * @param  CLKSource: specifies the SysTick clock source.
 *         This parameter can be one of the following values:
 *             @arg SYSTICK_CLKSOURCE_HCLK_DIV4: AHB clock divided by 4 selected as SysTick clock source.
 *             @arg SYSTICK_CLKSOURCE_HCLK: AHB clock selected as SysTick clock source.
 * @retval None
 */
void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource)
{
    /* Check the parameters */
    assert_param(IS_SYSTICK_CLK_SOURCE(CLKSource));
    if (CLKSource == SYSTICK_CLKSOURCE_HCLK)
    {
        SysTick->CTRL |= SYSTICK_CLKSOURCE_HCLK;
    }
    else
    {
        SysTick->CTRL &= ~SYSTICK_CLKSOURCE_HCLK;
    }
}

/**
 * @brief  This function handles SYSTICK interrupt request.
 * @retval None
 */
void HAL_SYSTICK_IRQHandler(void)
{
    HAL_SYSTICK_Callback();
}

/**
 * @brief  SYSTICK callback.
 * @retval None
 */
__weak void HAL_SYSTICK_Callback(void)
{
    /* NOTE : This function Should not be modified, when the callback is needed,
              the HAL_SYSTICK_Callback could be implemented in the user file
     */
}

/**
 * @}
 */

/**
 * @}
 */



#endif  /* HAL_CORTEX_MODULE_ENABLED */

/**
 * @}
 */

